# SPDX-FileCopyrightText: 2021 Daniel Vrátil <dvratil@kde.org>
#
# SPDX-License-Identifier: MIT

# Custom includes
include(GenerateHeaders)
include(AddQCoroLibrary)

include(CMakePackageConfigHelpers)

add_qcoro_library(
    NAME Coro
    INTERFACE
    NO_CMAKE_CONFIG
    INCLUDEDIR Coro
    CAMELCASE_HEADERS
        QCoro
        QCoroAsyncGenerator
        QCoroFwd
        QCoroGenerator
        QCoroLazyTask
        QCoroTask
    HEADERS
        concepts_p.h
        coroutine.h
        macros_p.h
        waitoperationbase_p.h
        impl/connect.h
        impl/lazytask.h
        impl/task.h
        impl/taskawaiterbase.h
        impl/taskbase.h
        impl/taskfinalsuspend.h
        impl/taskpromise.h
        impl/taskpromisebase.h
        impl/waitfor.h
    QT_LINK_LIBRARIES
        INTERFACE Core
)

if (NOT QCORO_DISABLE_DEPRECATED_TASK_H)
    # Install Task conditionally
    generate_headers(
        task_cc_HEADERS
        HEADER_NAMES Task
        OUTPUT_DIR QCoro
        ORIGINAL_HEADERS_VAR task_lc_HEADERS
    )

    install(
        FILES ${task_lc_HEADERS}
        DESTINATION ${QCORO_INSTALL_INCLUDEDIR}/qcoro/
        COMPONENT Devel
    )
    install(
        FILES ${task_cc_HEADERS}
        DESTINATION ${QCORO_INSTALL_INCLUDEDIR}/QCoro/
        COMPONENT Devel
    )
endif()


# The QCoroCoroConfig includes the QCoroMacros.cmake so we can't
# use the standard file generated by add_qcoro_library.
configure_package_config_file(
    "${CMAKE_CURRENT_SOURCE_DIR}/QCoroCoroConfig.cmake.in"
    "${CMAKE_CURRENT_BINARY_DIR}/QCoro${QT_VERSION_MAJOR}CoroConfig.cmake"
    INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/QCoro${QT_VERSION_MAJOR}Coro
    PATH_VARS CMAKE_INSTALL_INCLUDEDIR
)

write_basic_package_version_file(
    "${CMAKE_CURRENT_BINARY_DIR}/QCoro${QT_VERSION_MAJOR}CoroConfigVersion.cmake"
    VERSION ${qcoro_VERSION}
    COMPATIBILITY SameMajorVersion
)

# Install the extra macros file
install(
    FILES "QCoroMacros.cmake"
    DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${QCORO_TARGET_PREFIX}Coro/"
)

############################

add_subdirectory(core)

if (QCORO_WITH_QTDBUS)
    add_subdirectory(dbus)
endif()

if (QCORO_WITH_QTNETWORK)
    add_subdirectory(network)
endif()

if (QCORO_WITH_QTWEBSOCKETS)
    add_subdirectory(websockets)
endif()

if (QCORO_WITH_QTQUICK)
    add_subdirectory(quick)
endif()

if (QCORO_WITH_QML)
    add_subdirectory(qml)
endif()

if (QCORO_WITH_QTTEST)
    add_subdirectory(test)
endif()
